package org.example.route.controller.AdminController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.route.controller.UserController.LoginController;
import org.example.route.model.dto.*;
import org.example.route.model.pojo.Result;
import org.example.route.model.pojo.Train;
import org.example.route.model.vo.CarriageVO;
import org.example.route.model.vo.TrainVO;
import org.example.route.service.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/train")
@Slf4j
@Tag(name = "车次管理")
public class TrainController {
    @Autowired
    private TrainService trainService;



    //此部分包含定义车厢
    /**
     *
     *
     * 完成一测
     *
     * **/
    @Operation(summary = "添加列车")
    @PostMapping("/add")
    public Result add(@RequestBody TrainDTO trainDTO)
    {
        log.info("添加列车,{}",trainDTO);
        trainService.add(trainDTO);
        return Result.success();
    }

    /**完成一测**/
    @Operation(summary = "查询车次")
    @PostMapping("/list")
    public Result<List<TrainVO>> list(@RequestBody TrainQueryDTO trainQueryDTO)
    {
        log.info("查询车次,{}",trainQueryDTO);
        List<TrainVO> trainVOList = trainService.list(trainQueryDTO);
        return Result.success(trainVOList);
    }



    /**完成一测**/
    @Operation(summary = "修改车次状态")
    @PostMapping("/changeStatus")
    public Result changeStatus(@RequestBody TrainChangeStatusDTO trainChangeStatusDTO)
    {
        log.info("修改车次状态,{}",trainChangeStatusDTO);
        trainService.changeStatus(trainChangeStatusDTO);
        return Result.success();
    }

    //添加车厢

    /**完成一测**/
    @Operation(summary = "添加车厢")
    @PostMapping("/addCarriage")
    public Result addCarriage(@RequestBody TrainCarriageDTO trainCarriageDTO)
    {
        log.info("添加车厢,{}",trainCarriageDTO);
        trainService.addCarriage(trainCarriageDTO);
        return Result.success();
    }


    @Operation(summary = "删除列车")
    @PostMapping("/delete")
    public Result delete(@RequestBody BaseRequest baseRequest){
        log.info("删除列车,{}",baseRequest.getKey());
        trainService.delete(baseRequest);
        return Result.success();

    }



    @Operation(summary = "修改列车")
    @PostMapping("/update")
    public Result update(@RequestBody TrainDTO trainDTO){
        log.info("修改列车,{}",trainDTO);
        trainService.update(trainDTO);
        return Result.success();
    }

    @Operation(summary = "获取当前列车的车厢")
    @PostMapping("/listCarriageByTrain")
    public Result<List<CarriageVO>> listCarriageByTrain(@RequestBody TrainGradeDTO trainGradeDTO ){
        log.info("获取当前列车的车厢,{}",trainGradeDTO);
        return Result.success(trainService.listCarriageByTrain(trainGradeDTO));

    }



}
